package com.yyb.controller;

import com.yyb.annotation.AppPermission;
import com.yyb.annotation.Log;
import com.yyb.common.PageInfo;
import com.yyb.common.Result;
import com.yyb.domain.SysOperLog;
import com.yyb.dto.SysOperLogQueryDTO;
import com.yyb.enums.BusinessType;
import com.yyb.enums.ResultEnums;
import com.yyb.service.SysOperLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 描述: [操作日志相关接口]
 * 
 * 
 */
@RestController
@RequestMapping("sysOperLog")
@Tag(name = "操作日志相关接口")
public class SysOperLogController extends BaseController {


    @Resource
    private SysOperLogService sysOperLogService;

    /**
     * 分页查询操作日志
     * POST http://127.0.0.1:8080/sysOperLog/getByPage
     * 接口ID：148742213
     * 接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742213
     */
    @PostMapping("getByPage")
    @Operation(summary = "分页查询操作日志")
    @AppPermission("system:operLog:query")
    public Result<PageInfo<SysOperLog, SysOperLogQueryDTO>> getByPage(@RequestBody PageInfo<SysOperLog, SysOperLogQueryDTO> pageInfo) {
        PageInfo<SysOperLog, SysOperLogQueryDTO> info = this.sysOperLogService.getByPage(pageInfo);
        return new Result<>(info);
    }

    /**
     *根据ID删除操作日志
     *   DELETE http://127.0.0.1:8080/sysOperLog/delete/{operId}
     *   接口ID：148742216
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742216
     */
    @DeleteMapping("delete/{operId}")
    @AppPermission("system:operLog:remove")
    @Log(title = "操作日志-删除一个",businessType = BusinessType.DELETE)
    @Operation(summary = "根据ID删除操作日志")
    public Result<?> delete(@PathVariable Long operId) {
        int row = this.sysOperLogService.deleteByPrimaryKey(operId);
        return this.toAjax(row>0);
    }

    /**
     * 批量删除操作日志
     *   DELETE http://127.0.0.1:8080/sysOperLog/batchDelete/{ids}
     *   接口ID：148742231
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742231
     * @param operIds
     * @return
     */
    @DeleteMapping("batchDelete/{operIds}")
    @AppPermission("system:operLog:batchRemove")
    @Log(title = "操作日志-批量删除",businessType = BusinessType.DELETE)
    @Operation(summary = "批量删除操作日志")
    public Result<?> batchDelete(@PathVariable Long[] operIds) {
        if(operIds==null|| operIds.length==0){
            return new Result<>(ResultEnums.ERROR);
        }
        int row = this.sysOperLogService.deleteByPrimaryKeys(operIds);
        return this.toAjax(row>0);
    }

    /**
     * 清空操作日志
     *   DELETE http://127.0.0.1:8080/sysOperLog/cleanOperLog
     *   接口ID：148742232
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742232
     */
    @DeleteMapping("cleanOperLog")
    @AppPermission("system:operLog:clean")
    @Operation(summary = "清空登陆日志")
    @Log(title = "操作日志-清空",businessType = BusinessType.DELETE)
    public Result<?> cleanOperLog() {
        int row = this.sysOperLogService.deleteAllOperLog();
        return this.toAjax(row>0);
    }

}
